package com.abocode.aichat.server.modules.protocol.handler;

import com.abocode.aichat.server.channel.ChannelWrapper;
import com.abocode.aichat.server.context.ServerRuntimeContext;
import com.abocode.aichat.server.entity.Entity;
import com.abocode.aichat.server.entity.EntityImpl;
import com.abocode.aichat.server.modules.ModuleHandler;
import com.abocode.aichat.server.reply.Replies;
import com.abocode.aichat.server.stanza.Stanza;
import com.abocode.aichat.server.channel.ChannelWrapper;
import com.abocode.aichat.server.context.ServerRuntimeContext;
import com.abocode.aichat.server.entity.Entity;
import com.abocode.aichat.server.entity.EntityImpl;
import com.abocode.aichat.server.reply.Replies;
import com.abocode.aichat.server.stanza.Stanza;

import java.util.Map;

/**
 * Created by franky.
 */
public class ChatConfirmHandler implements ModuleHandler {
    public Replies execute(ChannelWrapper channelWrapper, Stanza stanza, ServerRuntimeContext serverRuntimeContext) {
        Map body = stanza.body();
        if (serverRuntimeContext.getMessageGatewayPipeline() == null) {
            throw new NullPointerException("confirm pipeline is null");
        }
        String jid = String.valueOf(body.get("jid"));
        Entity entity = EntityImpl.parse(jid);
        Map map=stanza.body();
        serverRuntimeContext.getMessageGatewayPipeline().confirm(entity,map.get("msgId"));
        return null;
    }

    public String module() {
        return "confirm";
    }
}
